package com.example.controller;

import com.example.Random;
import com.example.model.Course;
import com.example.model.Student;
import com.example.service.ChangeStudentService;
import com.example.service.StudentChooseCourseService;
import com.example.service.StudentService;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/student")
public class StudentController {

    @Autowired
    StudentService studentService;
    @Autowired
    ChangeStudentService changeStudentService;
    @Autowired
    StudentChooseCourseService studentChooseCourseService;



    @Autowired
    public StudentController(StudentService studentService) {
        this.studentService = studentService;
    }
@PostMapping("/login")

public Student login(HttpServletResponse response, @RequestBody Student student) {

    return studentService.login(response,student.getNumber(), student.getStudentPassword());


}
@GetMapping("/select")
public Student selectStudent(@RequestParam("number")String number){
        return studentService.selectStudentInfo(number);
}


    @PostMapping("/register")

    public String register(@RequestBody Student student) {
        student.setId(Random.rom());

       return studentService.register(student);
    }

//修改密码
    @PostMapping("/changeStudentPassword")
    public void changePassword(@RequestParam("password") String password, @RequestParam("number") String number){
        changeStudentService.changeStudentPassword(password, number);
    }
// 修改电话号码
   @PostMapping("/changeNumber")
    public void changeNumber(@RequestParam("number") String newNumber, String oldStudent1num){
        changeStudentService.changenumber(newNumber, oldStudent1num);
    }
//修改身份
    @PostMapping("/changeStudentIdentity")
    public void changeStudentRegister(String identity, String number){
        changeStudentService.changeStudentIdentity(identity, number);
    }
//修改个人信息
    @PostMapping("/changeStudentMsg")
    public void changeStudentMsg(@RequestBody Student student){
        changeStudentService.changeStudentMsg(student);
    }
//学生选课系统
    @PostMapping("/studentChooseCourse")
    public String studentChooseCourse(@RequestParam("courseId") String courseId, @RequestParam("number") String student_num){
        System.out.println(courseId+" "+student_num+"第一次");
       return studentChooseCourseService.studentChooseCourse( courseId, student_num);
    }
//学生退课
    @PostMapping("/studentDeleteCourse")
    public void studentDeleteCourse(@RequestParam("number") String add_course_num){
        System.out.println(add_course_num);
        studentChooseCourseService.studentDeleteCourse(add_course_num);
    }
//    返回学生所选课程的所有信息
    @GetMapping("/allCourse")
   public List<Course> allCourse(@RequestParam("number") String number){
      return studentChooseCourseService.selectAllCourse(number);
   }

}
